/*
 * hash.c (part of p8.c)
 *  
 *
 *  Created by Shang-Ju Chen on 3/5/11.
 *  
 *
 */

int
hash( char *s )
{
	int h,q;
	char *p;
	
	for ( p = s, q = 0; *p; q += (int) *p, p ++)
	{
	}
	
	h = (q % HSIZE) - 1;
	for (q = 0; ;)
	{
		if (HSIZE <= ++h)
		{
			h = 0;
		}
		if(hashp[h].ptss == (char*)NULL)
		{
			return(-(h+1));
		}
		if (strcmp(s,hashp[h].ptss) == 0)
		{
			return(h);
		}
		if(HSIZE <= ++q)
		{
			puts("** hash table overflow **");
			exit(1);
		}
	}
	
}
